<div class="doc-item" id="doc-1023"><h2 class="doc-item-name">make-map<span class="namespace">(clojure.contrib.command-line)</span></h2><ul class="var-arglists"><li>(<span class="var-name">make-map</span> args cmdspec)</li></ul><div class="var-source"><pre>; clojure/contrib/command_line.clj:18
(defn make-map [args cmdspec]
  (let [{spec true [rest-sym] false} (su/group-by vector? cmdspec)
        rest-str (str rest-sym)
        key-data (into {} (for [[syms [_ default]] (map #(split-with symbol? %)
                                                        (conj spec '[help? h?]))
                                sym syms]
                            [(re-find #&quot;^.*[^?]&quot; (str sym))
                             {:sym (str (first syms)) :default default}]))
        defaults (into {} (for [[_ {:keys [default sym]}] key-data
                                :when default]
                            [sym default]))]
    (loop [[argkey &amp; [argval :as r]] (if (seq args) args [&quot;--help&quot;])
           cmdmap (assoc defaults :cmdspec cmdspec rest-str [])]
      (if argkey
        (let [[_ &amp; [keybase]] (re-find #&quot;^--?(.*)&quot; argkey)]
          (cond
            (= keybase nil) (recur r (update-in cmdmap [rest-str] conj argkey))
            (= keybase &quot;&quot;)  (update-in cmdmap [rest-str] #(apply conj % r))
            :else (if-let [found (key-data keybase)]
                    (if (= \? (last (:sym found)))
                      (recur r (assoc cmdmap (:sym found) true))
                      (recur (next r) (assoc cmdmap (:sym found)
                                             (if (or (nil? r) (= \- (ffirst r)))
                                               (:default found)
                                               (first r)))))
                    (throw (Exception. (str &quot;Unknown option &quot; argkey))))))
        cmdmap))))</pre></div><div class="license"><p>Copyright (c) Rich Hickey. All rights reserved.</p><p>The use and distribution terms for this software are covered by the <a href="http://opensource.org/licenses/eclipse-1.0.php">Eclipse Public License 1.0</a>, which can be found in the file
          epl-v10.html at the root of this distribution. By using this software
          in any fashion, you are agreeing to be bound by the terms of this
          license. You must not remove this notice, or any other, from this
          software.</p></div></div>